import Vue from 'vue'
import Vuex from 'vuex'
import { fetchBidByBidId, fetchBidList, fetchBankList } from './api'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    bid: {},
    bids: {
      status: 0,
      message: 'success',
      body: {
        recommendedList:[]
      }
    },
    bankList:{}
  },

  actions: {
    FETCH_BID: ({commit, dispatch, state}, {bidId}) => {
      return fetchBidByBidId(bidId)
        .then((bid) => {
          commit('SET_BID', {bid})
        })
    },
    FETCH_BID_LIST: ({commit, dispatch, state}) => {
      return fetchBidList()
        .then((bids) => {
          commit('SET_BIDS', {bids})
        })
    },
    FETCH_BANK: ({commit, dispatch, state}, {type}) => {
      return fetchBankList(type)
        .then((bankList) => {
          commit('SET_TYPE', {bankList})
        })
    },
  },

  mutations: {
    SET_BID: (state, {bid}) => {
      state.bid = bid
    },
    SET_BIDS: (state, {bids}) => {
      state.bids = bids
    },
    SET_TYPE:(state, {bankList}) => {
      state.bankList = bankList
    }
  },

  getters: {
    
  }
})

export default store
